<template>
  <Card dis-hover :bordered="false">
    <Form inline>
      <Row>
        <Col span="19">
          <FormItem>
            <Input
              v-width="210"
              placeholder="请输入昵称/登录手机号/账号ID"
              v-model="params.keywords"
              @on-clear="searchData"
              @on-enter="searchData"
              clearable
            />
          </FormItem>
          <FormItem>
            <Select
              placeholder="请选择项目"
              v-width="120"
              v-model="params.project_id"
              :filterable="projectList.length >= 10"
              @on-open-change="showAll"
              @on-clear="searchData"
              @on-change="searchData"
              clearable
            >
              <Option
                v-for="item in projectList"
                :value="item.value"
                :key="item.value"
                >{{ item.label }}</Option
              >
            </Select>
          </FormItem>
          <FormItem>
            <TreeSelect
              v-width="150"
              placeholder="部门"
              v-model="params.department_id"
              :data="departmentList"
              @on-change="searchData"
              @on-clear="clearDep"
              clearable
            />
          </FormItem>
          <FormItem>
            <Select
              placeholder="请选择平台"
              v-width="120"
              v-model="params.platform_id"
              :filterable="platList.length >= 10"
              @on-open-change="showAll"
              @on-clear="searchData"
              @on-change="searchData"
              clearable
            >
              <Option
                v-for="item in platList"
                :value="item.value"
                :key="item.value"
                >{{ item.label }}</Option
              >
            </Select>
          </FormItem>
          <FormItem>
            <Select
              placeholder="认证医生"
              v-width="120"
              v-model="params.doctor_id"
              :filterable="doctorList.length >= 10"
              @on-open-change="showAll"
              @on-clear="searchData"
              @on-change="searchData"
              clearable
            >
              <Option
                v-for="item in doctorList"
                :value="item.value"
                :key="item.value"
                >{{ item.label }}</Option
              >
            </Select>
          </FormItem>
          <FormItem>
            <Select
              placeholder="请选择运营人"
              v-width="120"
              v-model="params.use_mid"
              :filterable="userList.length >= 10"
              @on-open-change="showAll"
              @on-clear="searchData"
              @on-change="searchData"
              clearable
            >
              <Option
                v-for="item in userList"
                :value="item.value"
                :key="item.value"
                >{{ item.label }}</Option
              >
            </Select>
          </FormItem>
          <FormItem>
            <Select
              placeholder="请选择状态"
              v-width="120"
              v-model="params.status"
              @on-clear="searchData"
              @on-change="searchData"
              clearable
            >
              <Option
                v-for="item in statusList"
                :value="item.value"
                :key="item.value"
                >{{ item.label }}</Option
              >
            </Select>
          </FormItem>
          <FormItem>
            <Select
              placeholder="是否投流"
              v-width="120"
              v-model="params.is_stream"
              @on-clear="searchData"
              @on-change="searchData"
              clearable
            >
              <Option
                v-for="item in streamList"
                :value="item.value"
                :key="item.value"
                >{{ item.label }}</Option
              >
            </Select>
          </FormItem>
        </Col>
        <Col span="5" style="text-align: right">
          <Button
            type="primary"
            @click="handleSet"
            :disabled="principalInfo.ids.length == 0"
            class="ivu-ml-8"
            v-hasC="{
              name: 'v1-buss-accounts-set-principal',
              flag: 'v1/buss/accounts/set-principal',
            }"
            >批量设置运营</Button
          >
          <Button
            type="primary"
            @click="handleAdd"
            class="ivu-ml-8"
            v-hasC="{
              name: 'v1-buss-accounts-update',
              flag: 'v1/buss/accounts/update',
            }"
            >新增</Button
          >
        </Col>
      </Row>
    </Form>
    <Table
      :columns="columns"
      :data="list"
      @on-selection-change="choseMuilt"
      :loading="loading"
      @on-sort-change="sortChange"
      :max-height="tableHeigth"
    >
      <template #status="{ row }">
        <Badge
          status="success"
          :text="row.status_name"
          v-if="row.status === '1'"
        />
        <Badge status="error" :text="row.status_name" v-else />
      </template>
      <template #login_passwd="{ row }">
        <p v-show="row.login_passwd">
          <span v-if="row.showPwd">{{ row.login_passwd }}</span>
          <span v-else>******</span>
          <Icon
            type="ios-eye-outline"
            :size="20"
            style="cursor: pointer"
            v-show="row.showPwd"
            @click="row.showPwd = false"
            v-hasC="{
              name: 'v1-buss-accounts-check-pwd',
              flag: 'v1/buss/accounts/check-pwd',
            }"
          />
          <Icon
            type="ios-eye"
            :size="20"
            style="cursor: pointer"
            v-show="!row.showPwd"
            @click="row.showPwd = true"
            v-hasC="{
              name: 'v1-buss-accounts-check-pwd',
              flag: 'v1/buss/accounts/check-pwd',
            }"
          />
        </p>
      </template>
      <template #fans_num="{ row }">
        {{ row.fans_num != null ? row.fans_num : "" }}
        <span v-if="row.rate > 0" style="color: #ed4014">
          <Icon type="ios-arrow-round-up" :size="20" />
          {{ row.rate }}
        </span>
        <span v-if="row.rate < 0" style="color: #19be6b">
          <Icon type="ios-arrow-round-down" :size="20" />
          {{ Math.abs(row.rate) }}
        </span>
      </template>
      <template #action="{ row }">
        <a
          @click="handleConsumption(row)"
          v-show="row.is_stream == 1 && row.status > 0"
          v-hasC="{
            name: 'v1-buss-accounts-consume',
            flag: 'v1/buss/accounts/consume',
          }"
          >消费</a
        >
        <a
          :disabled="true"
          v-show="row.is_stream == 0 || row.status < 1"
          v-hasC="{
            name: 'v1-buss-accounts-consume',
            flag: 'v1/buss/accounts/consume',
          }"
          >消费</a
        >
        <Divider
          type="vertical"
          v-hasC="{
            name: 'v1-buss-accounts-consume',
            flag: 'v1/buss/accounts/consume',
          }"
        />
        <a
          @click="handleUpdate(row)"
          v-hasC="{
            name: 'v1-buss-accounts-update-fans',
            flag: 'v1/buss/accounts/update-fans',
          }"
          >粉丝更新</a
        >
        <Divider
          type="vertical"
          v-hasC="{
            name: 'v1-buss-accounts-update-fans',
            flag: 'v1/buss/accounts/update-fans',
          }"
        />
        <a
          @click="handleEdit(row)"
          v-hasC="{
            name: 'v1-buss-accounts-update2',
            flag: 'v1/buss/accounts/update',
          }"
          >编辑</a
        >
        <Divider
          type="vertical"
          v-hasC="{
            name: 'v1-buss-accounts-update2',
            flag: 'v1/buss/accounts/update',
          }"
        />
        <a
          @click="handleDel(row.id)"
          class="del"
          v-hasC="{
            name: 'v1-buss-accounts-delete',
            flag: 'v1/buss/accounts/delete',
          }"
          >删除</a
        >
      </template>
    </Table>
    <Page
      class="ivu-mt-16"
      :total="total"
      :modelValue="params.current"
      :page-size="params.size"
      :page-size-opts="pageOpts"
      show-total
      show-sizer
      @on-change="changePage"
      @on-page-size-change="changepageSize"
    />
    <Modal
      :mask-closable="false"
      v-model="addModal"
      :width="700"
      :title="edit ? '新增' : '编辑'"
      :footer-hide="true"
      :draggable="true"
    >
      <Form ref="create" :model="accountInfo" :rules="rules" :label-width="100">
        <Row>
          <Col span="11">
            <FormItem label="平台" prop="platform_id" required>
              <Select
                v-model="accountInfo.platform_id"
                :filterable="platAddList.length >= 10"
                @on-open-change="showAll"
                placeholder="请选择平台"
                clearable
              >
                <Option
                  v-for="item in platAddList"
                  :value="+item.value"
                  :key="item.value"
                  >{{ item.label }}</Option
                >
              </Select>
            </FormItem>
            <FormItem label="昵称" prop="nickname" required>
              <Input
                v-model="accountInfo.nickname"
                placeholder="请输入昵称"
                :maxlength="30"
              />
            </FormItem>
            <FormItem label="账号ID" prop="account_name">
              <Input
                v-model="accountInfo.account_name"
                placeholder="请输入账号ID"
                :maxlength="30"
              />
            </FormItem>
            <FormItem label="类型" prop="t_id" required>
              <Select
                v-model="accountInfo.t_id"
                placeholder="请选择类型"
                @on-open-change="showAll"
                :filterable="cAddList.length >= 10"
                clearable
              >
                <Option
                  v-for="item in cAddList"
                  :value="+item.value"
                  :key="item.value"
                  >{{ item.label }}</Option
                >
              </Select>
            </FormItem>

            <FormItem label="项目" prop="project_id" required>
              <Select
                v-model="accountInfo.project_id"
                placeholder="请选择项目"
                :filterable="projectAddList.length >= 10"
                @on-open-change="showAll"
                @on-change="changePro"
                clearable
              >
                <Option
                  v-for="item in projectAddList"
                  :value="+item.value"
                  :key="item.value"
                  >{{ item.label }}</Option
                >
              </Select>
            </FormItem>
            <FormItem label="部门" prop="department_id" required>
              <TreeSelect
                style="width: 100%"
                placeholder="请选择部门"
                v-model="accountInfo.department_id"
                :data="departmentAddList"
                @on-change="changePro"
              />
            </FormItem>
            <FormItem label="认证医生" prop="doctor_id">
              <Select
                v-model="accountInfo.doctor_id"
                placeholder="请选择认证医生"
                :filterable="doctorAddList.length >= 10"
                @on-open-change="showAll"
                clearable
              >
                <Option
                  v-for="item in doctorAddList"
                  :value="+item.value"
                  :key="item.value"
                  >{{ item.label }}</Option
                >
              </Select>
            </FormItem>
            <FormItem label="运营人" prop="use_mid">
              <Select
                v-model="accountInfo.use_mid"
                :filterable="userAddList.length >= 10"
                @on-open-change="showAll"
                clearable
                placeholder="请选择运营人"
              >
                <Option
                  v-for="item in userAddList"
                  :value="+item.value"
                  :key="item.value"
                  >{{ item.label }}</Option
                >
              </Select>
            </FormItem>
          </Col>
          <Col span="2" class="ivu-text-center">
            <Divider type="vertical" style="height: 100%" />
          </Col>
          <Col span="11">
            <FormItem
              label="登录手机号"
              prop="login_account"
              :rules="{
                required: false,
                message: '请输入正确的联系号码',
                pattern: /^1\d{10}$/,
                trigger: 'blur',
              }"
            >
              <Input
                v-model="accountInfo.login_account"
                placeholder="请输入登录手机号"
                @input="
                  accountInfo.login_account = accountInfo.login_account.slice(
                    0,
                    11
                  )
                "
              />
            </FormItem>
            <FormItem label="登录密码" prop="login_passwd">
              <Input
                v-model="accountInfo.login_passwd"
                placeholder="请输入登录密码"
                :maxlength="30"
              />
            </FormItem>
            <FormItem label="登录设备" prop="login_device_id">
              <Select
                v-model="accountInfo.login_device_id"
                placeholder="请选择登录设备"
                @on-open-change="showAll"
                :filterable="equipmentAddList.length >= 10"
                clearable
              >
                <Option
                  v-for="item in equipmentAddList"
                  :value="+item.value"
                  :key="item.value"
                  >{{ item.label }}</Option
                >
              </Select>
            </FormItem>

            <FormItem label="注册日期" prop="accounts_reg_date" required>
              <DatePicker
                v-model="accountInfo.accounts_reg_date"
                :options="options"
                type="date"
                placeholder="日期选择"
              />
            </FormItem>
            <FormItem label="投流" prop="is_stream" required>
              <RadioGroup v-width="150" v-model="accountInfo.is_stream">
                <Radio :label="1">是</Radio>
                <Radio :label="0">否</Radio>
              </RadioGroup>
            </FormItem>
            <FormItem label="状态" prop="status">
              <Switch v-model="accountInfo.status" />
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div slot="footer" style="text-align: right">
        <Button type="default" @click="addModal = false">取消</Button>
        <Button
          type="primary"
          :loading="btnLoding"
          @click="ok"
          style="margin-left: 10px"
          >保存</Button
        >
      </div>
    </Modal>
    <Modal
      :mask-closable="false"
      v-model="selectModal"
      :width="400"
      title="批量设置运营"
      :footer-hide="true"
      :draggable="true"
    >
      <Form
        :label-width="90"
        :model="principalInfo"
        :rules="rules1"
        ref="principal"
      >
        <FormItem label="已选账号数">
          <span>{{ principalInfo.ids.length }}</span>
        </FormItem>

        <FormItem label="部门" prop="department_id" required>
          <TreeSelect
            style="width: 100%"
            placeholder="请选择部门"
            v-model="principalInfo.department_id"
            :data="departmentSetList"
            @on-change="changeSetPro"
          />
        </FormItem>
        <FormItem label="运营人" prop="use_mid" required>
          <Select
            placeholder="请选择运营人"
            :filterable="userSetList.length >= 10"
            @on-open-change="showAll"
            v-model="principalInfo.use_mid"
          >
            <Option
              v-for="item in userSetList"
              :value="item.value"
              :key="item.value"
              >{{ item.label }}</Option
            >
          </Select>
        </FormItem>
      </Form>
      <div slot="footer" style="text-align: right">
        <Button type="default" @click="selectModal = false">取消</Button>
        <Button
          type="primary"
          :loading="btnLoding"
          @click="save"
          style="margin-left: 10px"
          >保存</Button
        >
      </div>
    </Modal>
    <fansupdate
      :showFansupdate="showFansupdate"
      :accountId="accountId"
      @closefans="closefans"
    />
    <consumption
      ref="consumption"
      :id="accountId"
      :showConsumption="showConsumption"
      @closeConsumption="closeConsumption"
    />
  </Card>
</template>
<script>
import dayjs from "dayjs";
import consumption from "./consumption";
import fansupdate from "./fansupdate.vue";
import {
  accountList,
  createAccount,
  accountInfo,
  deleteAccount,
  accountSetPrincipal,
  getListByProject,
} from "@api/accountnumber.js";

export default {
  name: "accountnumber",
  components: { fansupdate, consumption },
  data() {
    return {
      tableHeigth: document.body.clientHeight - 270,
      addModal: false,
      selectModal: false,
      showFansupdate: false,
      showConsumption: false,
      edit: true,
      accountId: "",
      params: {
        keywords: "",
        project_id: "",
        platform_id: "",
        doctor_id: "",
        department_id: "",
        is_stream: "",
        use_mid: "",
        status: "",
        current: 1,
        size: 10,
        order_column: "",
        order_sort: "",
      },
      projectList: [],
      departmentList: [],
      platList: [],
      doctorList: [],
      userList: [],
      statusList: [],
      streamList: [
        {
          label: "是",
          value: 1,
        },
        {
          label: "否",
          value: 0,
        },
      ],
      cAddList: [],
      platAddList: [],
      userAddList: [],
      projectAddList: [],
      departmentAddList: [],
      doctorAddList: [],
      equipmentAddList: [],
      departmentSetList: [],
      userSetList: [],
      total: 0,
      pageOpts: [10, 20, 30, 40],
      columns: [
        {
          type: "selection",
          width: 60,
          align: "center",
          fixed: "left",
        },
        {
          key: "id",
          title: "ID",
          width: 80,
        },
        {
          key: "nickname",
          title: "昵称",
          ellipsis: "true",
          tooltip: "true",
          minWidth: 220,
        },
        {
          key: "account_name",
          title: "账号ID",
          ellipsis: "true",
          tooltip: "true",
          minWidth: 150,
        },
        {
          key: "t_name",
          title: "账号类型",
          width: 110,
        },
        {
          key: "doctor_name",
          title: "认证医生",
          width: 100,
        },
        {
          key: "platform_name",
          title: "平台",
          width: 100,
        },
        {
          key: "is_stream_str",
          title: "是否可投流",
          width: 118,
        },
        {
          slot: "fans_num",
          title: "粉丝数",
          width: 160,
          sortable: "custom",
        },
        {
          key: "project_name",
          title: "项目",
          width: 100,
        },
        {
          key: "department_name",
          title: "部门",
          width: 180,
        },
        {
          key: "login_device_name",
          title: "登录设备",
          ellipsis: "true",
          tooltip: "true",
          width: 150,
        },
        {
          key: "login_account",
          title: "登录手机号",
          width: 125,
        },
        {
          slot: "login_passwd",
          title: "登录密码",
          width: 160,
        },
        {
          slot: "status",
          title: "状态",
          width: 80,
        },
        {
          key: "use_mname",
          title: "运营人",
          width: 140,
        },
        {
          key: "accounts_reg_date",
          title: "注册日期",
          width: 110,
        },
        {
          slot: "action",
          title: "操作",
          width: 230,
          fixed: "right",
        },
      ],
      list: [],
      loading: false,
      btnLoding: false,
      accountInfo: {
        id: "",
        nickname: "",
        account_name: "",
        platform_id: "",
        t_id: "",
        doctor_id: "",
        login_device_id: "",
        is_stream: 0,
        login_account: "",
        login_passwd: "",
        use_mid: "",
        project_id: null,
        department_id: null,
        accounts_reg_date: this.$Date().format("YYYY-MM-DD"),
        status: true,
      },
      rules: {
        platform_id: [{ required: true, message: "请选择平台" }],
        department_id: [{ required: true, message: "请选择部门" }],
        project_id: [{ required: true, message: "请选择项目" }],
        nickname: [{ required: true, message: "请输入昵称" }],
        t_id: [{ required: true, message: "请选择类型" }],
        is_stream: [{ required: true, message: "请选择是否投流" }],
        accounts_reg_date: [{ required: true, message: "请选择注册日期" }],
      },
      rules1: {
        project_id: [{ required: true, message: "请选择项目" }],
        department_id: [{ required: true, message: "请选择部门" }],
        use_mid: [{ required: true, message: "请选择运营人" }],
      },
      principalInfo: {
        ids: [],
        department_id: null,
        use_mid: "",
      },
      options: {
        disabledDate(date) {
          return date && date.valueOf() > Date.now();
        },
      },
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    showAll(e) {
      if (e) {
        let downList = document.querySelectorAll(
          ".ivu-select-dropdown-list .ivu-select-item"
        );
        downList.forEach((item) => {
          item.style.display = "block";
        });
      }
    },
    handleConsumption(e) {
      this.showConsumption = true;
      this.accountId = e.id;
    },
    closeConsumption(state) {
      this.showConsumption = state;
    },
    sortChange(e) {
      this.params.order_column = e.key
        ? e.key.replace(/_str$/, "")
        : e.column.slot.replace(/_str$/, "");
      this.params.order_sort = e.order;
      this.getData();
    },
    choseMuilt(e) {
      let ids = [];
      e.forEach((item) => {
        ids.push(item.id);
      });
      this.principalInfo.ids = ids;
    },
    handleUpdate(info) {
      this.showFansupdate = true;
      this.accountId = info.id;
    },
    closefans(e, type) {
      this.showFansupdate = e;
      if (type == "update") {
        this.getData();
      }
    },
    //切换page
    changePage(index) {
      this.params.current = index;
      this.getData();
    },
    changepageSize(val) {
      this.params.size = val;
      this.getData();
    },
    handleDel(index) {
      this.$Modal.confirm({
        title: "删除提示",
        content: "是否确认删除此条记录，删除后不可恢复",
        onOk: () => {
          deleteAccount({ id: index })
            .then(() => {
              this.$Message.success("删除成功");
              this.getData();
            })
            .catch(() => {});
        },
      });
    },
    findUser(id, list) {
      return list.findIndex((item) => {
        return item.value == id;
      });
    },
    changePro() {
      getListByProject({
        project_id: this.accountInfo.project_id,
        department_id: this.accountInfo.department_id,
      }).then((res) => {
        this.doctorAddList = res.doctor;
        this.userAddList = res.principal_member;
        if (this.findUser(this.accountInfo.use_mid, this.userAddList) == -1) {
          this.accountInfo.use_mid = null;
        }
        if (
          this.findUser(this.accountInfo.doctor_id, this.doctorAddList) == -1
        ) {
          this.accountInfo.doctor_id = null;
        }
      });
    },
    handleAdd() {
      accountInfo().then((res) => {
        this.cAddList = res.condition.account_type;
        this.platAddList = res.condition.platform;
        this.doctorAddList = [];
        this.equipmentAddList = res.condition.device;
        this.projectAddList = res.condition.project;
        this.departmentAddList = this.changeData(res.condition.department_arr);
        this.accountInfo = {
          nickname: "",
          account_name: "",
          platform_id: "",
          t_id: "",
          project_id: null,
          department_id: null,
          doctor_id: "",
          login_device_id: "",
          is_stream: 0,
          login_account: "",
          login_passwd: "",
          use_mid: "",
          accounts_reg_date: this.$Date().format("YYYY-MM-DD"),
          status: true,
        };
        this.$nextTick(() => {
          this.$refs.create.resetFields();
        });
      });
      this.addModal = true;
      this.edit = true;
    },
    handleEdit(info) {
      this.addModal = true;
      this.edit = false;
      accountInfo({ id: info.id }).then((res) => {
        this.cAddList = res.condition.account_type;
        this.platAddList = res.condition.platform;
        this.userAddList = res.condition.principal_member;
        this.doctorAddList = res.condition.doctor;
        this.equipmentAddList = res.condition.device;
        this.projectAddList = res.condition.project;
        this.departmentAddList = this.changeData(res.condition.department_arr);
        this.accountInfo = {
          id: res.id,
          nickname: res.nickname,
          account_name: res.account_name,
          platform_id: +res.platform_id,
          t_id: +res.t_id,
          project_id: res.project_id ? +res.project_id : null,
          department_id: +res.department_id ? +res.department_id : null,
          doctor_id: +res.doctor_id,
          login_device_id: +res.login_device_id,
          is_stream: +res.is_stream,
          login_account: res.login_account,
          login_passwd: res.login_passwd,
          use_mid: +res.use_mid,
          accounts_reg_date: res.accounts_reg_date,
          status: res.status == 1 ? true : false,
        };
      });
    },
    handleSet() {
      this.selectModal = true;
      this.userSetList = [];
      this.principalInfo.use_mid = "";
      this.principalInfo.department_id = null;
      accountInfo().then((res) => {
        this.departmentSetList = this.changeData(res.condition.department_arr);
      });
      this.$refs.principal.resetFields();
    },
    changeSetPro(e) {
      getListByProject({
        department_id: this.principalInfo.department_id,
      }).then((res) => {
        this.userSetList = res.principal_member;
        if (this.findUser(this.principalInfo.use_mid, this.userSetList) == -1) {
          this.principalInfo.use_mid = null;
        }
      });
    },
    changeData(data) {
      data.forEach((item) => {
        item.value = +item.id;
        item.title = item.department_name;
        item.expand = true;
        if (item.children && item.children.length > 0) {
          this.changeData(item.children);
        }
      });
      return data;
    },
    getData() {
      this.loading = true;
      const params = {
        keywords: this.params.keywords,
        project_id: this.params.project_id,
        platform_id: this.params.platform_id,
        doctor_id: this.params.doctor_id,
        department_id: this.params.department_id,
        use_mid: this.params.use_mid,
        status: this.params.status,
        is_stream: this.params.is_stream,
        order_column: this.params.order_column,
        order_sort: this.params.order_sort,
        pageSize: this.params.size,
        page: this.params.current,
      };
      accountList(params)
        .then((res) => {
          this.projectList = res.condition.project_arr;
          this.platList = res.condition.platform_arr;
          this.doctorList = res.condition.doctors_arr;
          this.userList = res.condition.principal_member_arr;
          this.statusList = res.condition.status_arr;
          this.departmentList = this.changeData(res.condition.department_arr);
          res.list.forEach((item) => {
            item.showPwd = false;
          });
          this.list = res.list;
          this.total = res.total;
          this.loading = false;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    searchData() {
      this.params.current = 1;
      this.getData();
    },
    clearDep() {
      this.params.department_id = "";
      this.searchData();
    },
    addAccount() {
      this.btnLoding = true;
      const params = {
        nickname: this.accountInfo.nickname,
        account_name: this.accountInfo.account_name,
        platform_id: this.accountInfo.platform_id,
        t_id: this.accountInfo.t_id,
        doctor_id: this.accountInfo.doctor_id,
        project_id: this.accountInfo.project_id,
        department_id: this.accountInfo.department_id,
        login_device_id: this.accountInfo.login_device_id,
        is_stream: this.accountInfo.is_stream,
        login_account: this.accountInfo.login_account,
        login_passwd: this.accountInfo.login_passwd,
        use_mid: this.accountInfo.use_mid,
        accounts_reg_date: dayjs(this.accountInfo.accounts_reg_date).format(
          "YYYY-MM-DD"
        ),
        status: this.accountInfo.status ? 1 : 0,
      };
      if (this.edit) {
        createAccount(params)
          .then((res) => {
            this.$Message.success("录入成功");
            this.addModal = false;
            this.btnLoding = false;
            this.getData();
          })
          .catch(() => {
            this.btnLoding = false;
          });
      } else {
        createAccount(Object.assign({}, params, { id: this.accountInfo.id }))
          .then((res) => {
            this.$Message.success("编辑成功");
            this.addModal = false;
            this.btnLoding = false;
            this.getData();
          })
          .catch(() => {
            this.btnLoding = false;
          });
      }
    },
    ok() {
      this.$refs.create.validate((valid) => {
        if (valid) {
          this.addAccount();
        } else {
          this.addModal = true;
          return;
        }
      });
    },
    save() {
      this.$refs.principal.validate((valid) => {
        if (valid) {
          this.btnLoding = true;
          let params = {
            ids: this.principalInfo.ids.join(","),
            use_mid: this.principalInfo.use_mid,
            department_id: this.principalInfo.department_id,
          };
          accountSetPrincipal(params)
            .then((res) => {
              this.$Message.info({
                content: "已成功分配" + res.update_num + "条",
                duration: 5,
                closable: true,
              });
              this.btnLoding = false;
              this.selectModal = false;
              this.params.current = 1;
              this.getData();
            })
            .catch(() => {
              this.btnLoding = false;
            });
        }
      });
    },
  },
};
</script>
